/**
 * All rights reserved by www.xandroid.cn
 */
package xfok.net.xandroid.examples;

import xfok.net.xandroid.R;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * @author YangHua
 *  转载请注明出处：http://www.xfok.net/android/2010-5-20
 * 2010-5-20 www.xandroid.cn 
 */
public class Intents extends Activity implements OnClickListener{
	private static String TAG="Intents";	
	private Intent it;
	private Uri uri;
	private Button obs;
	private Button omp;
	private Button fpath;
	private Button sms;
	private Button sms2;
	private Button sms3;
	private Button tel;
	private Button tel2;
	private Button smail;
	private Button smail2;
	private Button smail3;
	private Button smail4;
	private Button pmp3;
	private Button pmp4;
	private Button sapp;
	private Button appi;
	private Button uapp;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.intents);
		obs=(Button)findViewById(R.id.obs);
		obs.setOnClickListener(this);
		omp=(Button)findViewById(R.id.omp);
		omp.setOnClickListener(this);
		fpath=(Button)findViewById(R.id.fpath);
		fpath.setOnClickListener(this);
		sms=(Button)findViewById(R.id.sms);
		sms.setOnClickListener(this);
		sms2=(Button)findViewById(R.id.sms2);
		sms2.setOnClickListener(this);
		sms3=(Button)findViewById(R.id.sms3);
		sms3.setOnClickListener(this);
		tel=(Button)findViewById(R.id.tel);
		tel.setOnClickListener(this);
		tel2=(Button)findViewById(R.id.tel2);
		tel2.setOnClickListener(this);
		smail=(Button)findViewById(R.id.smail);
		smail.setOnClickListener(this);
		smail2=(Button)findViewById(R.id.smail2);
		smail2.setOnClickListener(this);
		smail3=(Button)findViewById(R.id.smail3);
		smail3.setOnClickListener(this);
		smail4=(Button)findViewById(R.id.smail4);
		smail4.setOnClickListener(this);
		pmp3=(Button)findViewById(R.id.pmp3);
		pmp3.setOnClickListener(this);
		pmp4=(Button)findViewById(R.id.pmp4);
		pmp4.setOnClickListener(this);
		sapp=(Button)findViewById(R.id.sapp);
		sapp.setOnClickListener(this);
		appi=(Button)findViewById(R.id.appi);
		appi.setOnClickListener(this);
		uapp=(Button)findViewById(R.id.uapp);
		uapp.setOnClickListener(this);
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
			case R.id.obs:
				//打开浏览器
				uri = Uri.parse("http://www.google.com");   
				it = new Intent(Intent.ACTION_VIEW, uri);   
				startActivity(it);  
				break;
			case R.id.omp:
				//打开谷歌地图
				uri = Uri.parse("geo:38.899533,-77.036476");   
				it = new Intent(Intent.ACTION_VIEW, uri);    
				startActivity(it);    
				//其他 geo URI 範例   
				//geo:latitude,longitude   
				//geo:latitude,longitude?z=zoom   
				//geo:0,0?q=my+street+address   
				//geo:0,0?q=business+near+city   
				//google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom    
				break;
			case R.id.fpath:
				uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");   
				it = new Intent(Intent.ACTION_VIEW, uri);   
				startActivity(it);   
				//where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456   
				break;
			case R.id.sms:
				//调用短信程序  
				it = new Intent(Intent.ACTION_VIEW);   
				it.putExtra("sms_body", "The SMS text");    
				it.setType("vnd.android-dir/mms-sms");   
				startActivity(it);  
				break;
			case R.id.sms2:
				//传送消息  
				uri = Uri.parse("smsto://13681976851");   
				it = new Intent(Intent.ACTION_SENDTO, uri);   
				it.putExtra("sms_body", "The SMS text");   
				startActivity(it);  
				break;
			case R.id.sms3:
				//传送 MMS   
				uri = Uri.parse("content://media/external/images/media/23");   
				it = new Intent(Intent.ACTION_SEND);    
				it.putExtra("sms_body", "some text");    
				it.putExtra(Intent.EXTRA_STREAM, uri);   
				it.setType("image/png");    
				startActivity(it);   
				break;
			case R.id.tel:
				//叫出拨号程序  
				uri = Uri.parse("tel:13681976581");   
				it = new Intent(Intent.ACTION_DIAL, uri);   
				startActivity(it);   
				break;
			case R.id.tel2:
				//直接打电话出去   
				uri = Uri.parse("tel:13681976581");   
				it = new Intent(Intent.ACTION_CALL, uri);   
				startActivity(it);   
				//用這個，要在 AndroidManifest.xml 中，加上   
				//<uses-permission android:name="android.permission.CALL_PHONE" />   
				break;
			case R.id.smail:
				uri = Uri.parse("mailto:howard@xfok.net");   
				it = new Intent(Intent.ACTION_SENDTO, uri);   
				startActivity(it);   
				break;
			case R.id.smail2:
				it = new Intent(Intent.ACTION_SEND);   
				it.putExtra(Intent.EXTRA_EMAIL, "howard@xfok.net");   
				it.putExtra(Intent.EXTRA_TEXT, "The email body text");   
				it.setType("text/plain");   
				startActivity(Intent.createChooser(it, "Choose Email Client"));   
				break;
			case R.id.smail3:
				it=new Intent(Intent.ACTION_SEND);     
				String[] tos={"howard@xfok.net"};     
				String[] ccs={"hua.yang@springdesign.com"};     
				it.putExtra(Intent.EXTRA_EMAIL, tos);     
				it.putExtra(Intent.EXTRA_CC, ccs);     
				it.putExtra(Intent.EXTRA_TEXT, "The email body text");     
				it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");     
				it.setType("message/rfc822");     
				startActivity(Intent.createChooser(it, "Choose Email Client"));  
				break;
			case R.id.smail4:
				//传送附件 
				it = new Intent(Intent.ACTION_SEND);   
				it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
				it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");   
				it.setType("audio/mp3");   
				startActivity(Intent.createChooser(it, "Choose Email Client"));
				break;
			case R.id.pmp3:
				uri = Uri.parse("file:///sdcard/song.mp3");   
			    it = new Intent(Intent.ACTION_VIEW, uri);   
			    it.setType("audio/mp3");   
			    startActivity(it);  
				break;
			case R.id.pmp4:
				uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");   
			    it = new Intent(Intent.ACTION_VIEW, uri);   
			    startActivity(it); 
				break;
			case R.id.sapp:
				//寻找某个应用  
				uri = Uri.parse("market://search?q=google:pkg_name");  
				it = new Intent(Intent.ACTION_VIEW, uri);   
				startActivity(it);   
				//where pkg_name is the full package path for an application  
				break;
			case R.id.appi:
				 //显示某个应用的相关信息  
				uri = Uri.parse("market://details?id=app_id");   
				it = new Intent(Intent.ACTION_VIEW, uri);  
				startActivity(it);   
				//where app_id is the application ID, find the ID    
				//by clicking on your application on Market home    
				//page, and notice the ID from the address bar  
				break;
			case R.id.uapp:
				//Uninstall 应用程序 
				uri = Uri.fromParts("package", "pkg_name", null);  
				Intent it = new Intent(Intent.ACTION_DELETE, uri);    
				startActivity(it);   
				break;
		}
	}
	
}
